package serverMain;
// <editor-fold defaultstate="collapsed" desc="Imports">
import java.util.logging.Level;
import java.util.logging.Logger;
// </editor-fold> 

/**
 * @file ServerCounter.java
 *
 * @version 0.1
 * @author Chris Sewell 10008342
 */
public class ServerCounter {
    // <editor-fold defaultstate="collapsed" desc="Attributes">

    int countJava;
    int countPicture;
    int countBook;
    // </editor-fold> 
    // <editor-fold defaultstate="collapsed" desc="Constructors">

    public ServerCounter() {
        countJava = 0;
        countPicture = 0;
        countBook = 0;
    }
    // </editor-fold> 
    // <editor-fold defaultstate="collapsed" desc="Methods">

    /**
     * Synchronized methods These methods increment the counters for each file
     * when they are downloaded they are synchronized so only one thread can
     * call a method at any one time
     */
    public synchronized void incrementJavaCount() {//Increments java file counter and sleeps
        int tmp = countJava;
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(ServerCounter.class.getName()).log(Level.SEVERE, null, ex);
        }
        countJava = tmp + 1;
    }

    public synchronized void incrementPictureCount() {//Increments picture file counter and sleeps
        int tmp = countPicture;
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(ServerCounter.class.getName()).log(Level.SEVERE, null, ex);
        }
        countPicture = tmp + 1;
    }

    public synchronized void incrementBookCount() {//Increments book file counter and sleeps
        int tmp = countBook;
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(ServerCounter.class.getName()).log(Level.SEVERE, null, ex);
        }
        countBook = tmp + 1;
    }

    public int getJavaCount() {
        return countJava;
    }

    public int getPictureCount() {
        return countPicture;
    }

    public int getBookCount() {
        return countBook;
    }
    // </editor-fold> 
}
